package com.qfedu.yanglao20admin.bayonet.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.bayonet.BayonetManage;
import com.qfedu.yanglao20admin.bayonet.param.BayonetManageParam;
import com.qfedu.yanglao20admin.bayonet.service.BayonetManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "卡口管理")
@RestController
@RequestMapping("/manag")
public class BayonetManageController {

    @Resource
    private BayonetManageService bayonetManageService;

    @LogInfo
    @ApiOperation(value = "分页展示卡口管理", notes = "分页展示卡口管理")
    @GetMapping("/page")
    public CommonResult<BayonetManage> page(BayonetManageParam param) {
        Page<BayonetManage> bayonetManagePage = bayonetManageService.pageBayonetManage(param);
        return CommonResult.success(bayonetManagePage);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除卡口管理", notes = "根据id删除卡口管理")
    @GetMapping("/delete")
    public CommonResult<BayonetManage> deleteBayonetManage(@RequestParam @ApiParam("卡口管理id") Integer id) {
        bayonetManageService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加取卡口管理", notes = "添加取卡口管理")
    @PostMapping("/add")
    public CommonResult<BayonetManage> addBayonetManage(BayonetManage bayonetManage) {
        bayonetManageService.addBayonetManage(bayonetManage);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询卡口管理", notes = "根据id查询卡口管理")
    @GetMapping("/query")
    public CommonResult<BayonetManage> queryBayonetManage(@RequestParam @ApiParam("卡口管理id") Integer id) {
        BayonetManage bayonetManage = bayonetManageService.queryBayonetManage(id);
        return CommonResult.success(bayonetManage);
    }

    @LogInfo
    @ApiOperation(value = "修改卡口管理", notes = "修改卡口管理")
    @PostMapping("/update")
    public CommonResult<BayonetManage> updateBayonetManage(BayonetManage bayonetManage) {
        bayonetManageService.updateBayonetManage(bayonetManage);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "查询所有的卡口管理信息", notes = "查询所有的卡口管理信息")
    @GetMapping("/all")
    public CommonResult<BayonetManage> queryAllBayonetManage() {
        List<BayonetManage> bayonetManages = bayonetManageService.selectAllBayonet();
        return CommonResult.success(bayonetManages);
    }
}
